package com.wrial.simple;
/*
 * @Author  Wrial
 * @Date Created in 18:06 2020/3/26
 * @Description  实现 strStr()
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class LeetCode_28 {

    // 双指针
    public int strStr(String haystack, String needle) {

        int len = 0;
        if (needle == "") return 0;
        List<Integer> list = new ArrayList<>();
        char c = needle.charAt(0);
        for (int i = 0; i < haystack.length(); i++) {
            if (haystack.charAt(i) == c) {
                list.add(i);
            }
        }

        for (int i = 0; i < list.size(); i++) {
            int j = list.get(i);
            int k = 0;
            int tempLen = 0;
            while (true){
                if (haystack.charAt(j) == needle.charAt(k)){
                    tempLen++;
                    j++;
                    k++;
                }else {
                    len = len > tempLen ? len : tempLen;
                    break;
                }
            }



        }


        if (list.isEmpty()) return -1;

        return len;

    }

}
